package com.kaili.controller.web.v1;

import com.baomidou.mybatisplus.plugins.Page;
import com.kaili.pojo.dto.order.OrderAddBean;
import com.kaili.common.PageRequest;
import com.kaili.db.service.IHsOptOrderService;
import com.kaili.pojo.vo.OrderQueryVO;
import com.kaili.common.exception.BaseExcept;
import com.kaili.except.ResponseStatus;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xjh
 * @ClassName OrderController
 * @Description 订单处理接口
 * @Date 上午11:05 18-6-12
 * @Version 1.0
 */
@RestController
@RequestMapping("/operation/order")
@Api(tags = "订单服务", description = "订单相关API")
public class OrderController {

    @Autowired
    private IHsOptOrderService orderService;

    @PostMapping(value = "/doAddEwb")
    @ApiOperation(value = "新增在线下单", notes = "新增在线下单")
    public ResponseStatus doAddOrder(@RequestBody OrderAddBean addBean) {
        int ret = orderService.doAddOrder(addBean);
        if (ret != 0) {
            return ResponseStatus.ORDER_ADD_ERR;
        }
        return ResponseStatus.RESPONSE_OK;
    }



    @PostMapping("/queryOrderList")
    @ApiOperation(value = "分页查询订单数据列表")
    Page<OrderQueryVO> queryOrderList(@RequestBody PageRequest req) throws BaseExcept {
        if(req.getCur()!=null&&req.getPageSize()!=null){
            Page<OrderQueryVO> pager = new Page<OrderQueryVO>(req.getCur(), req.getPageSize());
            pager = orderService.queryOrderPageList(pager,req.getSearch());
            return pager;
        }
        throw new BaseExcept(ResponseStatus.ORDER_QUERY_ERR);
    }



}
